<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="店铺" prop="shopsName">
        <el-input
          v-model="queryParams.shopsName"
          placeholder="请输入店铺名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="serviceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="租赁服务ID" align="center" prop="rentalId" />
<!--      <el-table-column label="租赁编码" align="center" prop="rentalCore" />-->
      <el-table-column label="租赁名称" align="center" prop="rentalName" />
<!--      <el-table-column label="商品/施工队的供应商ID" align="center" prop="supplierId" />-->
      <el-table-column label="地区" align="center" prop="address" />

<!--      <el-table-column label="施工队的分类ID" align="center" prop="teamId" />-->
      <el-table-column label="租赁服务价格" align="center" prop="rentalPrice" />
      <el-table-column label="租赁地区" align="center" prop="rentalRegion" />
      <el-table-column label="店铺名称" align="center" prop="shopsName" />
<!--      <el-table-column label="施工队描述" align="center" prop="descript" />-->
      <el-table-column label="顺序 " align="center" prop="bianhao" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改租赁服务信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="顺序 " prop="bianhao">
          <el-input v-model="form.bianhao" placeholder="请输入顺序 " />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { zuLinEdit,zulinId,zulinList } from "../../../api/sequence";

  export default {
        name: "index",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 租赁服务信息表格数据
        serviceList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          rentalCore: null,
          rentalName: null,
          supplierId: null,
          teamId: null,
          rentalPrice: null,
          rentalRegion: null,
          publishStatus: null,
          descript: null,
          rentalStatus: null,
          modifiedTime: null,
          bianhao: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          rentalCore: [
            { required: true, message: "租赁编码不能为空", trigger: "blur" }
          ],
          rentalName: [
            { required: true, message: "租赁名称不能为空", trigger: "blur" }
          ],
          supplierId: [
            { required: true, message: "商品/施工队的供应商ID不能为空", trigger: "blur" }
          ],
          teamId: [
            { required: true, message: "施工队的分类ID不能为空", trigger: "blur" }
          ],
          rentalPrice: [
            { required: true, message: "租赁服务价格不能为空", trigger: "blur" }
          ],
          rentalRegion: [
            { required: true, message: "租赁地区不能为空", trigger: "blur" }
          ],
          publishStatus: [
            { required: true, message: "上下架状态：0上架下上架不能为空", trigger: "blur" }
          ],
          descript: [
            { required: true, message: "施工队描述不能为空", trigger: "blur" }
          ],
          rentalStatus: [
            { required: true, message: "删除状态：0未删除，1已删除不能为空", trigger: "blur" }
          ],
          modifiedTime: [
            { required: true, message: "最后修改时间不能为空", trigger: "blur" }
          ],
        }
      };
    },
    created() {
      this.getList();
    },

    methods: {
      /** 查询租赁服务信息列表 */
      getList() {
        this.loading = true;
        zulinList(this.queryParams).then(response => {
          this.serviceList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          rentalId: null,
          rentalCore: null,
          rentalName: null,
          supplierId: null,
          teamId: null,
          rentalPrice: null,
          rentalRegion: null,
          publishStatus: 0,
          descript: null,
          rentalStatus: 0,
          modifiedTime: null,
          bianhao: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.rentalId)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加租赁服务信息";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const rentalId = row.rentalId || this.ids
        zulinId(rentalId).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改租赁服务信息";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.rentalId != null) {
              zuLinEdit(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                }
              });
            } else {
              addService(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                }
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const rentalIds = row.rentalId || this.ids;
        this.$confirm('是否确认删除租赁服务信息编号为"' + rentalIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delService(rentalIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有租赁服务信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportService(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
      }
    }

    }
</script>

<style scoped>

</style>
